<?php namespace Admin\Controller;

/* 修改密码控制器*/
class UserController extends CommonController
{
	/*载入修改密码页面*/
	public function changePwd()
	{
		/*判断是都是post提交*/
	if(IS_POST)
	{
		$password = $_POST['password'];
		$newPassword = $_POST['newPassword'];
		$confirmPassword = $_POST['confirmPassword'];
		/*1.实例化模型User类*/
		$userModel = new \Common\Model\User;
		/*2.获取当前登陆用户的数据*/
		$data = $userModel->where("uid",$_SESSION['uid'])->first();
		p($data);
		/*如果旧密码不正确*/
		if($data['password'] !=md5($password))
		{
			 $this->error("旧密码输入错误");
		}
		
		/*走到这里说明输入的旧密码正确，可以验证新密码*/
		/*验证两次输入的密码是否一致*/
		if($newPassword !=$confirmPassword)
		{
			$this->error("两次密码输入不一致");
		}
		//执行修改
		$newPassword=md5($newPassword);
		$userModel->where("uid",$_SESSION['uid'])->Update(array('password'=>$newPassword));
		p($newPassword);
		//重新登陆
		session_unset();
		session_destroy();
		go("Login/index");
		
	}	

		View::make();
	}
}




















